//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<XDesktop.h>
///	@path	~/src/gui/xgui/
///	@date	2008/09/07
///	@desc	.

#pragma once

#include "xeres.h"

#include "lib/utilities/time.h"

#include "gui/xgui/XForm.h"

#include <map>

namespace xeres {

	// forward declaration
	class XFrame;
	
	/*! 
		\class	XDesktop
		\brief	General desktop.
	*/
	class XDesktop : public XForm
	{
	public:

		/// \ctor
		XDesktop( void );

		/// \dtor
		virtual ~XDesktop( void );

		DECL_IOBJECT_CLASS( XDesktop , XForm );

	public:

		/// \name Desktop Attributes
		//@{

		/// \brief	Get desktop origin point.
		virtual Pair<int> GetDesktopOrigin( void );

		/// \brief	Get desktop size.
		virtual Pair<int> GetDesktopSize( void );

		/// \brief	Get focusing area.
		virtual Rect<int> GetFocusArea( void );

		/// \brief	Set desktop origin point.
		virtual void SetDesktopOrigin( const Pair<int>& org );

		/// \brief	Set desktop size.
		virtual void SetDesktopSize( const Pair<int>& size );

		/// \brief	Attach frame.
		virtual void Attach( RefWeak<XFrame> frame );

		/// \brief	Detach form.
		virtual void Detach( RefWeak<XFrame> frame );

		//@}

		/// \name Window Management
		//@{

		/// \brief	Show window.
		virtual void ShowWindow( RefWeak<XFrame> frame , bool show , bool animate );

		/// \brief	Pin window to top.
		virtual void PinWindow( RefWeak<XFrame> frame , bool pin );

		/// \brief	Track tips.
		virtual void TrackTips( RefWeak<IGuiComp> comp , const WString& tips );

		/// \brief	Clear tips.
		virtual void ClearTips( void );

		/// \brief	On child repos.
		virtual void OnChildRepose( RefWeak<XFrame> comp );

		//@}

		/// \name XGui Component Attributes
		//@{

		/// \brief	Set position of component.
		virtual bool SetPosition( const Pair<int>& pos );

		/// \brief	Set size of component.
		virtual bool SetSize( const Pair<int>& size );

		/// \brief	Set placement.
		virtual bool SetPlacement( const Rect<int>& placement );

		/// \brief	Set parent component.
		virtual bool SetParent( RefWeak<IGuiForm> parent );

		/// \brief	Request update.
		virtual void RequestUpdate( RefWeak<IGuiComp> comp , const Rect<int>& region );

		/// \brief	Request show component.
		virtual void RequestShow( RefWeak<IGuiComp> comp , bool show );

		//@}

		/// \name XGUI Form Interface
		//@{

		/// \brief	Add child component.
		virtual bool AddChild( RefWeak<IGuiComp> comp );

		/// \brief	Del child component.
		virtual bool DelChild( RefWeak<IGuiComp> comp );

		//@}

		/// \name Message Passing
		//@{

		///	\brief	Process key input message.
		virtual HandleInput OnKeyInput( Updater& updater );

		///	\brief	Process mouse input message.
		virtual HandleInput OnMouseInput( Updater& updater );

		/// \brief	Call when mouse enter component.
		virtual void OnMouseEnter( Updater& updater , RefWeak<IGuiComp> last );

		/// \brief	Call when mouse leave component.
		virtual void OnMouseLeave( Updater& updater , RefWeak<IGuiComp> next );

		/// \brief	Call when focus in.
		virtual void OnFocusIn( Updater& updater , RefWeak<IGuiComp> last );

		/// \brief	Call when focus out.
		virtual void OnFocusOut( Updater& updater , RefWeak<IGuiComp> next );

		/// \brief	Call when close window.
		virtual void OnClose( void );

		//@}

		/// \brief	Get update needs.
		const Rect<int>& GetUpdateRegion( void );

		/// \brief	Accumulate update area.
		void AddUpdateRegion( const Rect<int>& region );

		/// \brief	Call after draw to validate update region..
		void ValidateDraw( void );

		/// \brief	Set on key handler.
		void SetOnKey( function<bool(int,KeyInput::Key,bool)> on_key ) { m_onKey = on_key; }

	protected:

		// @data

		// region needs to update
		Rect<int>						m_updateRect;

		// script handler
		function<bool(int,KeyInput::Key,bool)>	m_onKey;
	};

} // namespace xeres